import { Approval } from '../../types/index';
import { getTodoList } from '../../services/mockData';

Page({
  data: {
    todoList: [] as Approval[]
  },

  onLoad() {
    this.loadTodoList();
  },

  onShow() {
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 2
      });
    }
    this.loadTodoList();
  },

  onPullDownRefresh() {
    this.loadTodoList();
  },

  async loadTodoList() {
    const todoList = await getTodoList();
    this.setData({ todoList });
    wx.stopPullDownRefresh();
  },

  goToDetail(e: any) {
    const { id } = e.currentTarget.dataset;
    wx.navigateTo({
      url: `/pages/approvalDetail/approvalDetail?id=${id}`
    });
  }
}); 